<template>
  <div id="distribution_v2" v-show="boxShow">
    <c-title :text="agentSetTitle"></c-title>
    <div class="background_box">
      <div class="userbox">
        <div class="image">
          <img :src="userAvatar" alt="" />
        </div>
        <div class="userRight">
          <div class="name">{{ userName }}</div>
          <div class="ID">ID：{{ vipId }}</div>
          <div class="userRightL">
            <!-- <div class="levear" v-if="commissionArr.agent_level">{{ commissionArr.agent_level.name }}</div> -->
            <div class="levear" v-if="agent_level.name">{{ agent_level.name }}</div>
            <div class="ratio" v-if="first_level">{{ first_level }}%</div>
          </div>
        </div>
      </div>
    </div>
    <div class="main">
      <div class="detailBox">
        <div class="detailBox_top">
          <!-- <div class="tool" @click="show = true">推广工具<van-icon name="arrow-down" /></div> -->
          <div class="toolBox" id="extension-box">
            <div class="plugin-items-icon" v-for="icon in plugin_data" :key="icon.url" @click="pluginGoto(icon)">
              <i class="iconfont" :class="icon.class"></i>
              <span>{{ icon.title }}</span>
            </div>
          </div>

          <div class="withdraw" @click="WithdrawalTo">
            <div class="withdrawImg">
              <img src="../../assets/images/distribution/fontclass-daizhifu@2x.png" alt="" />
            </div>
            <div class="txt">提现</div>
          </div>
        </div>
        <div class="detailBox_bottom">
          <div class="child" @click="toastMethod(0)">
            <div class="txt">{{ count }}人</div>
            <div class="txt_t">我的粉丝</div>
          </div>
          <div class="child" @click="toastMethod(1)">
            <div class="txt">{{ $i18n.t("money") }}{{ commissionArr.order ? Number(commissionArr.order).toFixed(2) : "0.00" }}</div>
            <div class="txt_t">推广订单</div>
          </div>
          <div class="child" @click="toastMethod(2)">
            <div class="txt">{{ $i18n.t("money") }}{{ commissionArr.accumulated_commission }}</div>
            <div class="txt_t">累计{{ mail_commission_amount }}</div>
          </div>
          <div class="child" @click="toastMethod(3)">
            <div class="txt">{{ $i18n.t("money") }}{{ commissionArr.expect }}</div>
            <div class="txt_t">预计{{ mail_commission_amount }}</div>
          </div>
          <div class="child" @click="toastMethod(4)">
            <div class="txt">{{ $i18n.t("money") }}{{ commissionArr.unliquidated }}</div>
            <div class="txt_t">未结算{{ mail_commission_amount }}</div>
          </div>
          <div class="child" @click="toastMethod(5)">
            <div class="txt">{{ $i18n.t("money") }}{{ commissionArr.liquidated }}</div>
            <div class="txt_t">已结算{{ mail_commission_amount }}</div>
          </div>
        </div>
      </div>
      <div class="eChats-box">
        <div class="tab-head">
          <div class="tab-item" :class="[fans_type !== '1' ? 'active' : '']" @click="tabChange('fans_type', '')">粉丝裂变</div>
          <div class="tab-item" :class="[fans_type === '1' ? 'active' : '']" @click="tabChange('fans_type', '1')">粉丝转化</div>
        </div>
        <div>
          <div id="echats-fans" v-if="fans_type !== '1'" style="height: 220px; width: 21rem;"></div>
        </div>
        <div>
          <div id="echats-fans-line" v-if="fans_type === '1'" style="height: 220px; width: 21rem;"></div>
        </div>
        <div class="fans-box">
          <div class="fans-item" v-for="(fans, index) in fans_fission.data" :key="index">
            <p>{{ fans.value }}</p>
            <p>{{ fans.title }}</p>
          </div>
        </div>
      </div>
      <div class="record">
        <div class="tab-head">
          <div class="tab-item" :class="[recordType !== '1' ? 'active' : '']" @click="tabChange('recordType', '')">{{ mail_commission_amount }}记录</div>
          <div class="tab-item" :class="[recordType === '1' ? 'active' : '']" @click="tabChange('record_fans', '1')">推广粉丝</div>
        </div>
        <!-- 佣金记录 -->
        <div class="Commission_record" v-if="recordType != '1'">
          <div class="searchBox">
            <div class="top">
              <!-- 订单状态 -->
              <div class="orderStatus">
                <van-dropdown-menu>
                  <van-dropdown-item
                    @change="changeStatus"
                    v-model="order_status"
                    :title-class="'dropdownTitle'"
                    :title="option1[order_status] ? option1[order_status].text : '订单状态'"
                    :options="option1"
                  />
                </van-dropdown-menu>
              </div>
              <!-- 佣金状态 -->
              <div class="CommissionStatus">
                <van-dropdown-menu>
                  <van-dropdown-item
                    @change="changeStatus1"
                    v-model="Commission_status"
                    :title-class="'dropdownTitle'"
                    :title="option2[Commission_status] ? option2[Commission_status].text : `${mail_commission_amount}状态`"
                    :options="option2"
                  />
                </van-dropdown-menu>
              </div>
            </div>
            <div class="bottom">
              <div class="detail">
                <van-field v-model="searchKey" label-class="detailField" placeholder="订单号/下单会员信息" />
              </div>
              <div class="btnS" @click="btnSearch">搜索</div>
            </div>
          </div>
          <div class="Commission_recordList">
            <div class="lis" v-for="(item, index) in Commission_record.data" :key="index">
              <div class="orederTop">
                <div class="orederTop_t">
                  <div class="orederTop_t_txt" v-if="item.commission">{{ item.commission.order_sn }}({{ item.hierarchy == 1?Commission_record_set.name1:Commission_record_set.name2 }})</div>
                  <div class="orederTop_t_status" v-if="item.commission && Commission_record_set.commission_get_show == '1'">{{ item.commission.status_name }}</div>
                </div>
                <div class="orederTop_time" v-if="item.commission">
                  <div class="orederTop_time_left">{{ item.commission.created_at }}</div>
                  <div v-if="Commission_record_set.commission_get_show == '1'" class="orederTop_time_right">+{{ item.commission.commission }}</div>
                </div>
              </div>
              <div class="tab">
                <div class="tabsBox">
                  <template v-if="Commission_record_set.commission_detail_show == '1'">
                    <div class="tabNav" @click="navTap(item,index,0)">
                      <div class="txt" :class="!item.commissionTabs || item.commissionTabs == 0 ? 'txtLine selectTxt' :''">{{ mail_commission_amount }}信息</div>
                    </div>
                  </template>
                  <div class="tabNav" @click="navTap(item,index,1)">
                    <div class="txt" :class="item.commissionTabs == 1 || Commission_record_set.commission_detail_show != '1' ? 'txtLine selectTxt' :''">订单信息</div>
                  </div>
                </div>
                <!-- <van-tabs :color="subjectColor" :title-active-color="subjectColor">
                  <van-tab :title="`${mail_commission_amount}信息`"> -->
                  <template v-if="Commission_record_set.commission_detail_show == '1'">
                    <div class="tablis" v-if="!item.commissionTabs || item.commissionTabs == 0">
                        <div class="price" v-if="item.order">订单金额：{{ $i18n.t("money") }}{{ item.order.price }}</div>
                        <div class="price">计算金额：{{ $i18n.t("money") }}{{ item.commission_amount }}</div>
                        <div class="price" >计算方式：{{ item.formula }}</div>
                        <div class="price"  >{{ mail_commission_amount }}比例：{{ Number(item.commission_rate) }}%</div>
                    </div>
                  </template>
                  <!-- </van-tab> -->
                  <!-- <van-tab title="订单信息"> -->
                    <div class="orderLis" v-if="item.commissionTabs == 1">
                      <div class="goods" @click="toggle($event, item)">
                        <div class="goods_top">
                          <div class="time" v-if="item.order">下单时间：{{ timestampToTime(item.order.created_at) }}</div>
                          <div class="status">{{ item.order.status_name }}</div>
                        </div>
                        <template v-if="item.order_goods && Commission_record_set.open_order_detail == 1">
                          <div class="goodsbox" v-for="(good, ind) in item.order_goods" :key="ind">
                            <div class="image">
                              <img :src="good.thumb" alt="" />
                            </div>
                            <div class="goodsbox_right">
                              <div class="title">{{ good.title }}</div>
                              <div class="priceTotal">
                                <div class="price">{{ $i18n.t("money") }}{{ good.goods_price }}</div>
                                <div class="total">x {{ good.total }}</div>
                              </div>
                            </div>
                          </div>
                        </template>

                        <div class="actuallyPaid" v-if="item.order">实付：{{ $i18n.t("money") }}{{ item.order.price }}</div>
                      </div>
                      <div class="user" v-if="item.member">
                        <div class="userBox" v-if="Commission_record_set.open_order_buyer == 1">
                          <div class="image">
                            <img :src="item.member.avatar" alt="" />
                          </div>
                          <div class="userRight">
                            <div class="name">{{ item.member.realname }}</div>
                            <div class="wxname">微信号：{{ item.member.wechat ? item.member.wechat : "暂无微信号" }}</div>
                          </div>
                        </div>
                        <div class="consignee" v-if="item.order && Commission_record_set.open_order_buyer_info == 1">
                          <div class="txt" v-if="item.order.realname">收货人姓名：{{ item.order.realname }}</div>
                          <div class="txt" v-if="item.order.mobile">手机号：{{ item.order.mobile }}</div>
                        </div>
                      </div>
                    </div>
                  <!-- </van-tab> -->
                </van-tabs>
              </div>
            </div>
          </div>
        </div>
        <!-- 推广粉丝 -->
        <div class="fans-list" v-if="recordType === '1'">
          <div class="fans-item" v-for="order in extension_order.data" :key="order.order_sn">
            <img class="img" :src="order.avatar" alt="" />
            <div class="fans-item-right">
              <div class="fans-item-top">
                <p class="fans-name">
                  <span>{{ order.nickname }}</span> <span class="id">{{ order.child_id }}</span>
                </p>
                <p class="pay-box">
                  支付订单数: <span class="num">{{ order.order_price }}</span>
                </p>
              </div>
              <div class="fans-item-bottom">
                <span class="time">{{ order.created_at }}</span>
                <p class="pay-box">
                  支付订单总额: <span class="num">{{ $i18n.t("money") }}{{ order.order_count }}</span>
                </p>
              </div>
            </div>
          </div>
        </div>
        <div v-if="extension_order.data && extension_order.data.length <= 0" style="margin-top: 10px;">暂无数据</div>
      </div>
    </div>
    <!-- <van-popup v-model="show" :style="{ minHeight: '20%', borderRadius: '0.4688rem' }">
      <div class="plugin-items-box toolBox" id="extension-box">
        <div class="plugin-items-icon" v-for="icon in plugin_data" :key="icon.url" @click="pluginGoto(icon)">
          <i class="iconfont" :class="icon.class"></i>
          <span>{{ icon.title }}</span>
        </div>
      </div>
      <div class="txtClose" @click="show = false">关闭</div>
    </van-popup> -->
    <!--海报部分-->
    <yz-goodsposter v-model="posterShow" :posterData="poster_Data" :defaultImg="poster" :width="`18.875rem`" v-on:finish="uploadImageM"></yz-goodsposter>
    <!--海报部分end-->
  </div>
</template>
<script>
import distribution_v2 from "./distribution_controller_v2.js";
export default distribution_v2;
</script>
<style lang="scss" scoped>
#distribution_v2 {
  background: #f7f7f7;
  min-height: 100vh;
  padding-bottom: 2rem;
}

.txtClose {
  width: 3.4375rem;
  height: 1.375rem;
  background: var(--themeBaseColor);
  font-size: 0.625rem;
  border-radius: 0.125rem;
  line-height: 1.5rem;
  color: #2c2c2c;
  margin: 0 auto;
  margin-top: 0.9375rem;
  margin-bottom: 1rem;
}

.toolBox {
  flex: 1;
  width: 100%;
  overflow-x: auto;
  background: #fff;
  display: flex;
  justify-content: flex-start;
  padding-top: 0.9375rem;

  .plugin-items-icon {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    padding-right: 1rem;

    span {
      font-size: 12px;
    }

    .iconfont {
      display: inline-block;
      margin: 0 auto 5px auto;
      width: 2.5rem;
      height: 2.5rem;
    }
  }
}

.toolBox::-webkit-scrollbar {
  display: none;
}

.eChats-box {
  background-color: #fff;
  border-radius: 10px;
  margin: 0.625rem;
  padding: 0.3125rem;

  .fans-box {
    display: flex;
    overflow-x: scroll;
    word-break: keep-all;

    .fans-item {
      flex: 1;
      margin: 8px;
    }

    &::-webkit-scrollbar {
      display: none;
    }
  }

  .tab-head {
    display: flex;
    width: 20rem;
    margin: 0 auto;
    border-radius: 8px;
    background-color: #e9e9e9;

    .tab-item {
      flex: 1;
      padding: 6px 10px;
      color: #707070;

      &.active {
        background-color: var(--themeBaseColor);
        border-radius: 8px;
        color: #333;
      }
    }
  }
}

.main {
  margin-top: -10rem;

  .record {
    .Commission_record {
      padding: 0.7813rem 0.625rem;

      .Commission_recordList {
        margin-top: 0.625rem;

        .tab {
          .tabsBox {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .tabNav {
              flex: 1;
              display: flex;
              align-items: center;
              justify-content: center;

              .txt {
                padding: 0.625rem 0;
                position: relative;
              }

              .selectTxt {
                color: var(--themeBaseColor);
              }

              .txtLine::after {
                content: '';
                position: absolute;
                bottom: 0;
                left: 5%;
                width: 90%;
                height: 0.17rem;
                background: var(--themeBaseColor);
                border-radius: 4px;
                // border-bottom: 3px solid var(--themeBaseColor);
              }
            }
          }

          .orderLis {
            margin-top: 0.9375rem;

            .user {
              padding: 0.625rem 0 0 0;

              .consignee {
                font-size: 0.625rem;
                color: #2c2c2c;
                margin-top: 0.9063rem;
                display: flex;
                flex-wrap: wrap;

                .txt {
                  flex: 1;
                  text-align: left;
                }
              }

              .userBox {
                display: flex;
                justify-content: space-between;

                .userRight {
                  flex: 1;
                  height: 1.875rem;
                  display: flex;
                  flex-direction: column;
                  justify-content: space-between;
                  font-size: 0.6875rem;
                  align-items: flex-start;

                  .name {
                    line-height: 0.6875rem;
                    color: #2c2c2c;
                  }

                  .wxname {
                    line-height: 0.6875rem;
                    color: #666;
                    font-weight: 300;
                  }
                }

                .image {
                  width: 1.875rem;
                  height: 1.875rem;
                  background: #ccc;
                  border-radius: 0.125rem;
                  margin-right: 0.4063rem;

                  img {
                    width: 1.875rem;
                    height: 1.875rem;
                    border-radius: 0.125rem;
                  }
                }
              }
            }

            .goods {
              border-bottom: 1px solid #f4f4f4;

              .actuallyPaid {
                flex: 1;
                text-align: right;
                font-size: 0.625rem;
                color: #2c2c2c;
                line-height: 1.5rem;
              }

              .goodsbox {
                margin-top: 0.7813rem;
                display: flex;
                justify-content: space-between;

                .goodsbox_right {
                  flex: 1;
                  display: flex;
                  flex-direction: column;
                  justify-content: space-between;

                  .priceTotal {
                    display: flex;
                    justify-content: space-between;
                    font-size: 0.625rem;
                    color: #999;
                  }

                  .title {
                    text-align: left;
                    font-size: 0.6875rem;
                    color: #2c2c2c;
                  }
                }

                .image {
                  width: 2.1875rem;
                  height: 2.1875rem;
                  border-radius: 0.125rem;
                  background: #ccc;
                  margin-right: 0.375rem;

                  img {
                    width: 100%;
                    height: 100%;
                    border-radius: 0.125rem;
                  }
                }
              }

              .goods_top {
                display: flex;
                align-items: center;
                justify-content: space-between;

                .time {
                  font-size: 0.625rem;
                  color: #6b6b6b;
                }

                .status {
                  color: #ff5a5a;
                  font-size: 0.625rem;
                }
              }
            }
          }

          .tablis {
            margin-top: 0.9375rem;
            display: flex;
            flex-wrap: wrap;

            .price {
              min-width: 50%;
              text-align: left;
              font-size: 0.6875rem;
              color: #2c2c2c;
              line-height: 1.5rem;
            }
          }
        }

        .lis {
          background: #fff;
          padding: 0.625rem;
          margin-bottom: 0.625rem;

          .orederTop {
            padding-bottom: 0.625rem;
            border-bottom: 1px solid #f4f4f4;

            .orederTop_time {
              margin-top: 0.3125rem;
              display: flex;
              align-items: center;
              justify-content: space-between;

              .orederTop_time_left {
                font-size: 0.625rem;
                color: #6b6b6b;
              }

              .orederTop_time_right {
                font-size: 0.8125rem;
                color: #202020;
              }
            }

            .orederTop_t {
              display: flex;
              align-items: center;
              justify-content: space-between;

              .orederTop_t_txt {
                font-size: 0.8125rem;
                color: #292929;
              }

              .orederTop_t_status {
                font-size: 0.6875rem;
                color: #ff5a5a;
              }
            }
          }
        }
      }

      .searchBox {
        .bottom {
          display: flex;

          .btnS {
            width: 3.75rem;
            height: 1.875rem;
            background: var(--themeBaseColor);
            border-radius: 0.3125rem;
            text-align: center;
            line-height: 1.875rem;
            font-size: 0.6875rem;
            margin-left: 0.625rem;
          }

          .detail {
            width: 12.5rem;
            height: 1.875rem;
            background: #fff;
            border-radius: 0.3125rem;
            padding: 0 0.5938rem;
            line-height: 1.875rem;
            text-align: left;
            color: #6b6b6b;
            font-size: 0.6875rem;

            .van-cell {
              padding: 0 !important;
              line-height: 1.875rem;
            }

            .detailField {
              height: 100%;
              line-height: 1.875rem;
              color: #6b6b6b !important;
            }
          }
        }

        .top {
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-bottom: 0.625rem;
        }

        .orderStatus,
        .CommissionStatus {
          background: #fff;
          padding: 0 0.625rem;
          width: 10.7813rem;
          height: 1.875rem;
          display: flex;
          justify-content: space-between;
          align-items: center;
          overflow: hidden;
          border-radius: 0.3125rem;
          color: #6b6b6b;
          font-size: 0.6875rem;

          ::v-deep .dropdownTitle {
            color: #6b6b6b;
            font-size: 0.6875rem;
            width: 10.7813rem;
            display: flex;
          }

          ::v-deep .van-dropdown-menu__title::after {
            position: absolute;
            top: 50%;
            right: 20px;
            margin-top: -5px;
            border: 3px solid;
            border-color: transparent transparent #dcdee0 #dcdee0;
            -webkit-transform: rotate(-45deg);
            transform: rotate(-45deg);
            opacity: 0.8;
            content: "";
          }
        }
      }
    }

    .tab-head {
      display: flex;
      width: 20rem;
      margin: 0 auto;
      border-radius: 8px;
      background-color: #e9e9e9;

      .tab-item {
        flex: 1;
        padding: 6px 10px;
        color: #707070;

        &.active {
          background-color: var(--themeBaseColor);
          border-radius: 8px;
          color: #333;
        }
      }
    }

    .fans-list {
      background: #fff;
      display: flex;
      flex-direction: column;

      .fans-item {
        background-color: #fff;
        padding: 8px;
        margin-bottom: 10px;
        border-radius: 5px;
        display: flex;

        .img {
          flex: 0 0 35px;
          width: 35px;
          height: 35px;
          border-radius: 50%;
          margin-right: 5px;
        }

        .fans-item-right {
          display: flex;
          flex-direction: column;
          flex: 1;
          max-width: 88%;
        }

        .fans-item-top,
        .fans-item-bottom {
          display: flex;
          justify-content: space-between;
        }

        .fans-item-top {
          margin-bottom: 5px;

          .fans-name {
            font-size: 13px;
            font-weight: bold;
            text-align: left;
            display: inline-block;
            max-width: 65%;
          }

          .id {
            background-color: #fff1f1;
            border-radius: 9px;
            color: #ff5a5a;
            font-weight: normal;
            font-size: 11px;
            padding: 3px 5px;
          }
        }

        .time {
          font-size: 11px;
          color: #6b6b6b;
        }

        .pay-box {
          font-size: 11px;

          .num {
            color: #ff5a5a;
          }
        }
      }

      .fans-item:first-child {
        margin-top: 10px;
      }
    }
  }

  .detailBox {
    margin: 0 0.625rem;
    min-height: 12.8125rem;
    background: #fff;
    border-radius: 0.625rem;
    padding: 0 0.625rem 0.7188rem 0.625rem;

    .detailBox_bottom {
      margin: 0 0.625rem;
      background: #fff9e8;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      margin-top: 1rem;
      padding: 1.0313rem 0;

      .child:nth-child(n + 3) {
        margin-bottom: 0;
      }

      .child {
        width: 33.33%;
        overflow: hidden;
        text-align: center;
        margin-bottom: 1.4375rem;

        .txt {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 0.875rem;
          line-height: 1.5rem;
        }

        .txt_t {
          font-size: 0.6875rem;
          line-height: 1.5rem;
          color: #5d5d5d;
        }
      }
    }

    .detailBox_top {
      margin: 0 0.1563rem;
      border-bottom: 0.0313rem #f3f3f3 solid;
      display: flex;
      justify-content: space-between;

      .withdraw {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-right: 0.625rem;
        padding-left: 1.0938rem;
        box-shadow: -0.1875rem 0 0.25rem -0.0938rem rgba(0, 0, 0, 0.2);
        margin-top: 0.5rem;
        padding-top: 0.325rem;
        padding-bottom: 0.325rem;

        .txt {
          font-size: 0.6875rem;
          font-weight: 1.25rem;
          line-height: 1.25rem;
        }

        .withdrawImg {
          width: 1.125rem;
          height: 1.125rem;

          img {
            width: 100%;
            height: 100%;
          }
        }
      }

      .tool {
        height: 1.4375rem;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        font-size: 0.6875rem;
        padding: 0.375rem 0.6875rem 0.375rem 0.625rem;
        border-radius: 6px;
        background: var(--themeBaseColor);
        margin-top: 0.7813rem;
        font-weight: 500;

        i {
          margin-left: 0.1563rem;
        }
      }
    }
  }
}

.background_box {
  color: #382c0a;
  background-color: #fff;
  background-image: -webkit-gradient(linear, left top, left bottom, from(var(--themeBaseColor)), to(#f5f5f5));
  background-image: -webkit-linear-gradient(var(--themeBaseColor), #f5f5f5);
  background-image: linear-gradient(var(--themeBaseColor), #f5f5f5);
  min-height: 18.1875rem;
  padding: 1.5938rem 1.0938rem 0 1.0938rem;

  .userbox {
    display: flex;

    .userRight {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: flex-start;

      .name {
        font-size: 1rem;
        font-weight: bold;
        color: #574502;
        line-height: 1.5rem;
      }

      .ID {
        font-size: 0.8125rem;
        font-weight: 400;
        color: #333;
        line-height: 1.5rem;
      }

      .userRightL {
        display: flex;
        font-size: 0.625rem;
        line-height: 0.625rem;
        margin-top: 0.3125rem;
      }

      .levear,
      .ratio {
        background: #cb5600;
        padding: 0.3438rem 0.4688rem;
        margin-right: 0.4375rem;
        color: #fff;
        border-radius: 0.1875rem;
      }
    }

    .image {
      width: 2.8125rem;
      height: 2.8125rem;
      border-radius: 100%;
      flex-shrink: 0;
      margin-right: 0.6563rem;

      img {
        width: 100%;
        height: 100%;
        border-radius: 100%;
      }
    }
  }
}
</style>